package com.example.industry.service.impl;

import com.example.industry.dao.ProjectDao;
import com.example.industry.entity.Project;
import com.example.industry.entity.User;
import com.example.industry.enums.Roles;
import com.example.industry.service.ProjectService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProjectServiceImpl implements ProjectService
{
    @Resource
    private ProjectDao projectDao;

    @Override
    public boolean createProject(String projectName, Integer chairmanId, String projectIntroduction)
    {
        // TODO： 一个用户不能创建重名的项目
//        Set<Project> projectSet = getChairmanProjects(chairmanId);
//        for (Project project : projectSet)
//        {
//            if (projectName.equals(project.getProjectName()))
//            {
//                return false;
//            }
//        }

        Project newProject = new Project();
        newProject.setProjectName(projectName);
        newProject.setChairmanId(chairmanId);
        newProject.setProjectIntroduction(projectIntroduction);
        return projectDao.addProject(newProject);
    }

    @Override
    public boolean deleteProjectById(Integer projectId)
    {
        return projectDao.deleteById(projectId);
    }

    @Override
    public boolean updateProject(Integer projectId, String projectName, String projectIntroduction)
    {
        Project project = projectDao.findById(projectId);
        project.setProjectName(projectName);
        project.setProjectIntroduction(projectIntroduction);
        return projectDao.update(project);
    }

    @Override
    public List<User> findUsersByProjectIdAndRole(Integer projectId, Roles role)
    {
        // TODO 获取一个项目的成员, 指定角色
//        ResultSet resultSet = projectDao.findUsersByProjectIdAndRole(projectId, role);

//        List<String> membersInfo = new ArrayList<>();
//        while (resultSet.next())
//        {
//            membersInfo.add(userDao.findById(Integer.parseInt(resultSet.getString("user_id"))).toString() + "Role is " + resultSet.getString("role"));
//        }
        return null;
    }

    @Override
    public boolean deleteUserInProjectByUserId(Integer projectId, Integer userId)
    {
        return projectDao.deleteMember(projectId, userId);
    }

}
